﻿using MvcArchStarter.Core.Persistence;
using MvcArchStarter.Domain;
using MvcArchStarter.WebUI.Controllers.PostsCommands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcArchStarter.WebUI.Controllers
{
    public class PostsController : Controller
    {
        private IUnitOfWork _uow;
        public PostsController(IUnitOfWork uow)
        {
            _uow = uow;
        }

        public ActionResult Index(GetBlogCommand getBlogCommand)
        {
            getBlogCommand.UnitOfWork = _uow;
            var blog = getBlogCommand.Execute();
            return View(blog);
        }

        public ActionResult CreateBlogEntry(GetBlogCommand getBlogCommand)
        {
            ViewData.TemplateInfo.HtmlFieldPrefix = "ViewModel";
            getBlogCommand.UnitOfWork = _uow;
            var blog = getBlogCommand.Execute();

            var post = new Post { Blog = blog, BlogId = blog.BlogID, DatePosted = DateTime.Now };

            return View(post);
        
        
        }

        public ActionResult SaveBlogEntry(PostBlogPostCommand post)
        {
            post.UnitOfWork = _uow;

            post.Execute();
            return null;
        }

    }
}
